/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.google.common.collect.ImmutableSet;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.AttributeFlag;
/*     */ import com.zimbra.cs.account.AttributeManager;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.io.PrintStream;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetDomainInfo
/*     */   extends AdminDocumentHandler
/*     */ {
/*  40 */   private static final Set<String> bootstrapInfoAttrs = ImmutableSet.of("zimbraSkinLogoURL", "zimbraSkinLogoAppBanner", "zimbraSkinLogoLoginBanner", "zimbraAdminConsoleLoginURL", "zimbraWebClientLoginURL", "zimbraWebClientLoginURLAllowedUA", new String[] { "zimbraWebClientLoginURLAllowedIP", "zimbraWebClientLogoutURL", "zimbraWebClientLogoutURLAllowedUA", "zimbraWebClientLogoutURLAllowedIP", "zimbraWebClientMaxInputBufferLength", "zimbraSkinBackgroundColor", "zimbraSkinForegroundColor", "zimbraSkinSecondaryColor", "zimbraSkinSelectionColor" });
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  59 */     ZimbraSoapContext lc = getZimbraSoapContext(context);
/*  60 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  62 */     AuthToken at = lc.getAuthToken();
/*  63 */     boolean hasAuth = at != null;
/*     */     
/*     */ 
/*  66 */     boolean applyConfig = request.getAttributeBool("applyConfig", true);
/*  67 */     Element d = request.getElement("domain");
/*  68 */     String key = d.getAttribute("by");
/*  69 */     String value = d.getText();
/*     */     
/*  71 */     Key.DomainBy domainBy = Key.DomainBy.fromString(key);
/*  72 */     Domain domain = prov.getDomain(domainBy, value, true);
/*  73 */     Element response = lc.createElement(AdminConstants.GET_DOMAIN_INFO_RESPONSE);
/*     */     
/*  75 */     if ((domain == null) && (domainBy != Key.DomainBy.name) && (domainBy != Key.DomainBy.virtualHostname))
/*     */     {
/*     */ 
/*  78 */       toXML(response, prov.getConfig(), applyConfig, hasAuth);
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     }
/*     */     else
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  97 */       if (domain == null) {
/*  98 */         if (domainBy == Key.DomainBy.virtualHostname) {
/*  99 */           domain = prov.getDomain(Key.DomainBy.name, value, true);
/*     */         }
/* 101 */         if (domain == null) {
/* 102 */           domain = findDomain(prov, value);
/*     */         }
/*     */       }
/* 105 */       if (domain != null) {
/* 106 */         toXML(response, domain, applyConfig, hasAuth);
/*     */       } else {
/* 108 */         toXML(response, prov.getConfig(), applyConfig, hasAuth);
/*     */       }
/*     */     }
/* 111 */     return response;
/*     */   }
/*     */   
/*     */   private void addAttrElementIfNotNull(Entry entry, Element element, String key) throws ServiceException {
/* 115 */     if (AttributeManager.getInstance().isMultiValued(key)) {
/* 116 */       for (String value : entry.getMultiAttr(key)) {
/* 117 */         element.addNonUniqueElement("a").addAttribute("n", key).setText(value);
/*     */       }
/*     */     } else {
/* 120 */       String value = entry.getAttr(key, null);
/* 121 */       if (value != null) {
/* 122 */         element.addNonUniqueElement("a").addAttribute("n", key).setText(value);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private void toXML(Element e, Entry entry, boolean applyConfig, boolean hasAuth) throws ServiceException {
/* 128 */     Element domain = e.addElement("domain");
/* 129 */     if (!hasAuth) {
/* 130 */       domain.addAttribute("name", "VALUE-BLOCKED");
/* 131 */       domain.addAttribute("id", "VALUE-BLOCKED");
/* 132 */       if (entry != null) {
/* 133 */         for (String attr : bootstrapInfoAttrs) {
/* 134 */           addAttrElementIfNotNull(entry, domain, attr);
/*     */         }
/*     */       }
/* 137 */       return;
/*     */     }
/* 139 */     if ((entry instanceof Domain)) {
/* 140 */       Domain d = (Domain)entry;
/* 141 */       domain.addAttribute("name", d.getUnicodeName());
/* 142 */       domain.addAttribute("id", d.getId());
/*     */     }
/*     */     else {
/* 145 */       domain.addAttribute("name", "globalconfig");
/* 146 */       domain.addAttribute("id", "globalconfig-dummy-id");
/*     */     }
/* 148 */     Set<String> attrList = AttributeManager.getInstance().getAttrsWithFlag(AttributeFlag.domainInfo);
/* 149 */     Map attrsMap = entry.getUnicodeAttrs(applyConfig);
/*     */     
/* 151 */     for (String name : attrList) {
/* 152 */       Object value = attrsMap.get(name);
/*     */       
/* 154 */       if ((value instanceof String[])) {
/* 155 */         String[] sv = (String[])value;
/* 156 */         for (int i = 0; i < sv.length; i++)
/* 157 */           domain.addElement("a").addAttribute("n", name).setText(sv[i]);
/* 158 */       } else if ((value instanceof String)) {
/* 159 */         domain.addElement("a").addAttribute("n", name).setText((String)value);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/* 164 */   private static Domain findDomain(Provisioning prov, String value) throws ServiceException { Domain domain = null;
/*     */     
/* 166 */     int firstDotAt = value.indexOf('.');
/* 167 */     int secondDotAt = firstDotAt == -1 ? -1 : value.indexOf('.', firstDotAt + 1);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 172 */     while (secondDotAt != -1)
/*     */     {
/* 174 */       domain = prov.getDomain(Key.DomainBy.name, value.substring(firstDotAt + 1), true);
/* 175 */       if (domain != null) {
/*     */         break;
/*     */       }
/* 178 */       firstDotAt = secondDotAt;
/* 179 */       secondDotAt = value.indexOf('.', firstDotAt + 1);
/*     */     }
/*     */     
/*     */ 
/* 183 */     return domain;
/*     */   }
/*     */   
/*     */   public boolean needsAuth(Map<String, Object> context)
/*     */   {
/* 188 */     return false;
/*     */   }
/*     */   
/*     */ 
/*     */   public boolean needsAdminAuth(Map<String, Object> context)
/*     */   {
/* 194 */     return false;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 199 */     notes.add("Do not need any right, all admins are allowed.");
/*     */   }
/*     */   
/*     */ 
/*     */   public static void main(String[] args)
/*     */     throws ServiceException
/*     */   {
/* 206 */     findDomain(Provisioning.getInstance(), "x.y.z.a.b.c");System.out.println();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetDomainInfo.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */